package router

import (
	api "gitee.com/xuesongtao/collect/app/api"
	ser "gitee.com/xuesongtao/collect/app/service"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/os/gcron"
	"github.com/gogf/gf/os/glog"
)

func init() {
	s := g.Server()
	s.SetDumpRouterMap(false)
	s.EnablePProf()

	// 路由注册
	s.Group("/", func(group *ghttp.RouterGroup) {
		group.GET("/collect/healthy", api.Healthy) // health
	})

	// 注册定时任务
	registerCron()
}

// registerCron 注册定时任务
func registerCron() {
	glog.Info("register cron")

	// 采集 errLog
	gcron.AddSingleton(g.Cfg().GetString("pusherrlog.cron_tab"), func() {
		glog.Info("CronCollectErrLog2Push starting...")
		ser.CronCollectErrLog2Push()
		glog.Info("CronCollectErrLog2Push end")
	}, "CronCollectErrLog2Push")

	// TODO // 延迟推送消息
	// gcron.AddSingleton(g.Cfg().GetString("delayhandle.cron_tab"), func() {
	// 	glog.Info("HandleDelayPush starting...")
	// 	service.HandleDelayPush()
	// 	glog.Info("HandleDelayPush end")
	// }, "HandleDelayPush")
}
